cmake_minimum_required(VERSION 3.16)
project(untitled C)

set(CMAKE_C_STANDARD 99)

#加入一个配置头文件用于处理CMake对源码的设置
configure_file(
        "${PROJECT_SOURCE_DIR}/config.h.in"
        "${PROJECT_BINARY_DIR}/config.h"
)

#是否使用自己的testfunc库
option(USE_MYTEST
        "Use provided math implementation" ON)

#是否加入testfunc库
if (USE_MYTEST)
    include_directories("${PROJECT_SOURCE_DIR}/test")
    add_subdirectory(test)
    set (EXTRA_LIBS ${EXTRA_LIBS} testfunc)
endif(USE_MYTEST)

#查找当前目录下的所有源文件
#并将名称保存到DIR_SRCS变量
aux_source_directory(. DIR_SRCS)
#添加math子目录
#add_subdirectory(test)
#add_executable(untitled main.c test.c test.h)
#指定生成目标
add_executable(untitled ${DIR_SRCS})

#添加链接库
target_link_libraries(untitled ${EXTRA_LIBS})

#cmake -G "MinGW Makefiles"
#在windows下生成Makefile

#cmake -G "MinGW Makefiles" -D USE_MYTEST=off
#cmake -G "MinGW Makefiles" -D USE_MYTEST=on